﻿'========================================================================
'功能:資產商業邏輯物件
'作者:andy
'日期: 2011/1/31
'========================================================================

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Namespace AssetManage.BBL
    Public Class AssetBBL
        ''' <summary>
        ''' 取得員工所屬公司的行事曆的工作日日曆PS:目前先以日曆天計算
        ''' </summary>
        ''' <param name="dd">某一日</param>
        ''' <param name="days">N天(負數代表是往前推)</param>
        ''' <param name="UID">員工</param>
        ''' <param name="dbName">資料庫名稱</param>
        ''' <returns>取得員工所屬公司的行事曆的工作日日曆PS:目前先以日曆天計算</returns>
        ''' <remarks>取得員工所屬公司的行事曆的工作日日曆PS:目前先以日曆天計算</remarks>
        Public Function GetWorkDate(ByVal dd As DateTime, ByVal days As Integer, ByVal UID As String, ByVal dbName As String) As DateTime
            Return dd.AddDays(days)
        End Function

        Public Function GetAssetData1(ByVal assetdef_id As String, ByVal asset_owner As String, ByVal asset_SerialNo As String, ByVal Dept As String, ByVal HouseID As String, ByVal MAC As String, ByVal ComputerName As String, ByVal IP As String, ByVal asset_status As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetData1(assetdef_id, asset_owner, asset_SerialNo, Dept, HouseID, MAC, ComputerName, IP, asset_status)
        End Function


        Public Sub InsertReSendMailLog(ByVal AssetNo As String, ByVal UID As String, ByVal dbName As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.InsertReSendMailLog(AssetNo, UID)

        End Sub


        Public Function GetAssetResendData(ByVal dbName As String) As DataSet
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetResendData()
        End Function

        Public Function GetOAStatus(ByVal kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetOAStatus(kind)
        End Function
        Public Function GetOAUsingType(ByVal kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetOAUsingType(kind)
        End Function

        Public Function GetOAFactory(ByVal kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetOAFactory(kind)
        End Function
        Public Function GetOAStoreHouse(ByVal kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetOAStoreHouse(kind)
        End Function

        ''' <summary>e
        ''' 取得某一員工所有資產或某一類別資產
        ''' </summary>
        ''' <param name="AssetType">資產類別空白代表全部</param>
        ''' <param name="UserID">員工編號</param>
        ''' <returns>取得某一員工所有資產或某一類別資產</returns>
        ''' <remarks>取得某一員工所有資產或某一類別資產</remarks>
        Public Function GetAssetDataByAssettypeUID(ByVal AssetType As String, ByVal UserID As String, ByVal dbName As String) As DataSet
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetDataByAssettypeUID(AssetType, UserID)
        End Function

        ''' <summary>
        ''' 新增一筆資料到Log中,並且將已回報的資料清除
        ''' </summary>
        ''' <param name="AssetNo">資產編號</param>
        ''' <param name="UID">員工編號</param>
        ''' <param name="ReturnDeadLine">回報截止日</param>
        ''' <param name="ResendDays">重送天數</param>
        ''' <param name="ResendTimes">重送次數</param>
        '''<param name="MailSubject">主旨</param>
        ''' <param name="MailBody">內容</param>
        ''' <remarks></remarks>
        Public Sub InsertSendMailLog(ByVal AssetNo As String, ByVal UID As String, ByVal ReturnDeadLine As DateTime, ByVal ResendDays As Integer, ByVal ResendTimes As Integer, ByVal MailSubject As String, ByVal MailBody As String, ByVal ParamID As Integer, ByVal dbName As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.InsertSendMailLog(AssetNo, UID, ReturnDeadLine, ResendDays, ResendTimes, MailSubject, MailBody, ParamID)
        End Sub
        Public Sub InsertSendMailLogWS(ByVal AssetNo As String, ByVal UID As String, ByVal ReturnDeadLine As DateTime, ByVal ResendDays As Integer, ByVal ResendTimes As Integer, ByVal MailSubject As String, ByVal MailBody As String, ByVal ParamID As Integer, ByVal dbName As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.InsertSendMailLogWS(AssetNo, UID, ReturnDeadLine, ResendDays, ResendTimes, MailSubject, MailBody, ParamID)
        End Sub
        ''' <summary>
        ''' 取得資產類別資料
        ''' </summary>
        ''' <param name="kind">0=正常,1=加一筆空白</param>
        ''' <param name="dbName">資料庫代號</param>
        ''' <returns>取得資產類別資料</returns>
        ''' <remarks>取得資產類別資料</remarks>
        Public Function GetAssetType(ByVal kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetType(kind)
        End Function

        ''' <summary>
        ''' 取得目前資料庫中資產的數量合計資料,依owner及資產類型來分開計算
        ''' </summary>
        ''' <param name="AssetType">資產類型</param>
        ''' <param name="DeptNo">部門代號</param>
        ''' <param name="TakeOfficeDate">到職日</param>
        ''' <param name="HouseID">庫別1.個人,2.虛擬0全部</param>
        ''' <param name="TopN">數量前N名</param>
        ''' <param name="EquQty">數量N以上</param>
        ''' <param name="dbName">資料庫代號</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetAssetGroupData(ByVal AssetType As String, ByVal DeptNo As String, ByVal TakeOfficeDate As String, ByVal HouseID As String, ByVal TopN As String, ByVal EquQty As String, ByVal UserID As String, ByVal AssetNo As String, ByVal dbName As String) As DataSet
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetGroupData(AssetType, DeptNo, TakeOfficeDate, HouseID, TopN, EquQty, UserID, AssetNo)
        End Function
        Public Function GetAssetData(ByVal assetdef_id As String, ByVal asset_owner As String, ByVal asset_SerialNo As String, ByVal Dept As String, ByVal HouseID As String, ByVal MAC As String, ByVal ComputerName As String, ByVal IP As String, ByVal asset_status As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetData(assetdef_id, asset_owner, asset_SerialNo, Dept, HouseID, MAC, ComputerName, IP, asset_status)
        End Function


        Public Function GetAssetReturnData(ByVal assetdef_id As String, ByVal asset_owner As String, ByVal asset_SerialNo As String, ByVal Kind As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName) 'Kind=1 : 回報'Kind=2 :取消回報
            Return db1.GetAssetReturnData(assetdef_id, asset_owner, asset_SerialNo, Kind)
        End Function


        '''' <summary>
        '''' 新增OA資產回報紀錄
        '''' </summary>
        '''' <param name="AsseetNo">資產編號</param>
        '''' <param name="AssetType">資產型態</param>
        '''' <param name="Owner">資產保管人</param>
        '''' <param name="sendMan">寄信人/SYstem</param>
        '''' <param name="ReplyDeadLine">回報截止日</param>
        '''' <param name="ResendDays">重送天數</param>
        '''' <param name="ResendTimes">重送次數</param>
        '''' <param name="dbName">資料庫代號</param>
        '''' <remarks></remarks>
        'Public Sub InsertAssetReplyLog(ByVal AsseetNo As String, ByVal AssetType As String, ByVal Owner As String, ByVal sendMan As String, ByVal ReplyDeadLine As String, ByVal ResendDays As Integer, ByVal ResendTimes As Integer, ByVal dbName As String)
        '    Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
        '    db1.InsertAssetReplyLog(AsseetNo, AssetType, Owner, sendMan, ReplyDeadLine, ResendDays, ResendTimes)
        'End Sub


        Public Sub SaveAssetData(ByVal UsingType2 As String, ByVal StoreHouse As String, ByVal StoreLocation As String, ByVal User2 As String, ByVal UID As String, ByVal asset_serialNo As String, ByVal dbName As String, ByVal UsingDesc As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.SaveAssetData(UsingType2, StoreHouse, StoreLocation, User2, UID, asset_serialNo, UsingDesc)
        End Sub
        Public Sub SaveAssetData(ByVal vo As AssetManage.VO.AssetVO, ByVal dbName As String, ByVal webPath As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.SaveAssetData(vo, webPath)
        End Sub
        ''' <summary>
        ''' (取消)回報修改資料及新增1筆(取消)回報log
        ''' </summary>
        ''' <param name="asset_serialNo">資產編號</param>
        ''' <param name="byWho">執行人</param>
        ''' <param name="CancelReason">取消原因選項</param>
        ''' <param name="CancelRemark">取消說明</param>
        '''  <param name="ModiType">異動種類: 0:.新增1.異動2.移轉3.回報4.繳回5.取消回報6.寄信</param>
        ''' <remarks> (取消)回報修改資料及新增1筆(取消)回報log</remarks>
        Public Sub UpdateReply(ByVal asset_serialNo As String, ByVal byWho As String, ByVal CancelReason As String, ByVal CancelRemark As String, ByVal ModiType As String, ByVal dbName As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.UpdateReply(asset_serialNo, byWho, CancelReason, CancelRemark, ModiType)
        End Sub

        ''' <summary>
        ''' 取得型號的設定價格
        ''' </summary>
        ''' <param name="FactoryID">廠區</param>
        ''' <param name="Model">型號</param>
        ''' <returns>取得型號的設定價格</returns>
        ''' <remarks>取得型號的設定價格</remarks>
        Public Function GetAssetCost(ByVal FactoryID As String, ByVal Model As String, ByVal dbName As String) As String
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetAssetCost(FactoryID, Model)
        End Function
        Public Function GetUnReplyData(ByVal def_id As String, ByVal Owner As String, ByVal asset_serialNo As String, ByVal Dept As String, ByVal HouseID As String, ByVal ReturnDeadLine1 As DateTime, ByVal ReturnDeadLine2 As DateTime, ByVal SendType As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetUnReplyData(def_id, Owner, asset_serialNo, Dept, HouseID, ReturnDeadLine1, ReturnDeadLine2, SendType)
        End Function

        Public Function GetReplyStatistics(ByVal Kind As String, ByVal assetdef_id As String, ByVal dept As String, ByVal ReturnDeadLine1 As DateTime, ByVal ReturnDeadLine2 As DateTime, ByVal HouseID As String, ByVal dbName As String) As DataTable
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.GetReplyStatistics(Kind, assetdef_id, dept, ReturnDeadLine1, ReturnDeadLine2, HouseID)

        End Function


        Public Sub InsertAssetData(ByVal vo As AssetManage.VO.AssetVO, ByVal webPath As String, ByVal dbName As String)
            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            db1.InsertAssetData(vo, webPath)
        End Sub

        ''' <summary>
        ''' 取得目前每個人的總數,欄位會橫排
        ''' </summary>
        ''' <param name="deptno"></param>
        ''' <param name="asset_owner"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function getUserAssetSum(ByVal deptno As String, ByVal asset_owner As String, ByVal asset_defid As String, ByVal dbName As String) As DataTable

            Dim db1 As AssetManage.DAO.AssetDAO = New AssetManage.DAO.AssetDAO(dbName)
            Return db1.getUserAssetSum(deptno, asset_owner, asset_defid)
        End Function

    End Class
End Namespace

